package netty.byteBuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.embedded.EmbeddedChannel;

public class PooledByteBuf {

    EmbeddedChannel embeddedChannel = new EmbeddedChannel();

    private void init() {
        embeddedChannel.config().setAllocator(PooledByteBufAllocator.DEFAULT);
//        embeddedChannel.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
    }

    public void start() {
        for (int i = 0; i < 1024*1024; i++) {
            ByteBuf buffer = embeddedChannel.alloc().buffer(1024);
            embeddedChannel.write(buffer);
        }
    }

    public static void main(String[] args) {
        new PooledByteBuf().init();
        new PooledByteBuf().start();
    }
}
